Skip to content

Conversation

@Cherry
Copy link
Contributor

@Cherry Cherry commented Jan 31, 2025

Fixes #1023

@Cherry Cherry changed the title fix: default connections in cloudflare to lower fix: default max connections in cloudflare to lower Jan 31, 2025
@porsager
Copy link
Owner

That's a compiled file, so the change will be removed on publish.

@Cherry
Copy link
Contributor Author

Cherry commented Jan 31, 2025

Ah I see, sorry. Would it make sense to add this to the transpile.cf.js file instead?

@Cherry
Copy link
Contributor Author

Cherry commented Apr 6, 2025

Let me know if you'd like to see any other changes here @porsager. It'd be good to get this merged to prevent this common footgun!

@porsager porsager force-pushed the master branch 2 times, most recently from 4fd011e to a92f470 Compare May 20, 2025 23:40
@porsager porsager force-pushed the master branch 2 times, most recently from 4a0fe34 to 3a43815 Compare November 12, 2025 04:40
@Cherry
Copy link
Contributor Author

Cherry commented Nov 12, 2025

Let me know if there's anything else I can do to get this landed @porsager, thanks!

@porsager
Copy link
Owner

Hi James.. Yes - let's get this finished.

I'm wondering if maybe dynamic resolution is better? If we at one point can move the Cloudflare polyfill I'm afraid we'll forget the max: 3 limit.

Is there an env var we could rely on in cloudflare or perhaps a global?

@Cherry
Copy link
Contributor Author

Cherry commented Nov 12, 2025

Cloudflare does make globalThis.Cloudflare available on any modern workers (I'm not 100% certain if this is available on older service worker formatted Workers), which might suffice for checking? Alternatively, we could add a test that just asserts the output for the cloudflare build to have max: 3 which should catch any regressions?

@Cherry
Copy link
Contributor Author

Cherry commented Nov 12, 2025

Something like this should work after the defaults setting:

  // Adjust max connections for Cloudflare Workers
  // https://github.com/porsager/postgres/issues/1023
  if (typeof globalThis !== 'undefined' && 'Cloudflare' in globalThis) {
    defaults.max = 3;
  }

Happy to do that if preferred, let me know!

@porsager
Copy link
Owner

Cool! globalThis is available on all supported platforms, so if you add it as a ternary to defaults like this instead that'd be great!

max : globalThis.Cloudflare ? 3 : 10

A nice and simple one line PR ;)

@Cherry
Copy link
Contributor Author

Cherry commented Nov 12, 2025

Done, thanks! Let me know if any other changes are needed.

@porsager
Copy link
Owner

porsager commented Nov 12, 2025

Nice - just remove the changes to everything but src/index.js as those are built automatically anyway. Also remove the comment - git keeps enough history ;)

@porsager porsager changed the base branch from master to cf-hyperdrive November 12, 2025 17:12
@porsager porsager changed the base branch from cf-hyperdrive to master November 12, 2025 17:12
@Cherry Cherry force-pushed the fix/cf-max-connections branch from 5f3645f to 27b6370 Compare November 12, 2025 17:31
@Cherry
Copy link
Contributor Author

Cherry commented Nov 12, 2025

Sounds good, done, thanks

@porsager porsager merged commit 94b7170 into porsager:master Nov 12, 2025
54 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Default connections to less than 10 in Cloudflare Workers environment to avoid deadlock

2 participants